<template>
  <div id="edit">
   <van-nav-bar title="我是前辈" left-arrow>
    <template #left>
      <van-icon 
      name="arrow-left" 
      @click="onClickLeft"
      size="20"/>
    </template>
   </van-nav-bar>

    <div class="information">
      <van-form @submit="onSubmit">
        <van-field
          v-model="real_name"
          name="real_name"
          label="真实姓名"
          placeholder="请填写真实姓名"
          :rules="[{ required: true, message: '请填写真实姓名' }]"
        />
        <van-field
          v-model="age"
          name="age"
          label="年龄"
          placeholder="请填写真实年龄"
          :rules="[{ required: true, message: '请填写真实年龄' }]"
        />
        <van-field
          v-model="school"
          name="school"
          label="毕业院校"
          placeholder="请填写毕业院校"
          :rules="[{ required: true, message: '请填写毕业院校' }]"
        />
        <van-field
          v-model="production"
          name="production"
          rows="10"
          autosize
          label="个人简介"
          type="textarea"
          placeholder="请输入个人简介"
        />
        <div style="margin: 16px;">
          <van-button class="button" native-type="submit">确认</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import axios from 'axios';
import{Toast} from 'vant';

export default {
data(){
    return{
        real_name:'',
        age:'',
        school:'',
        production:'',
        // uploader: [],
    }
},
methods:{
      onSubmit(values) {
        console.log('submit', values);

         let user_id = localStorage.getItem("login_user_id");

          axios
          .get("/api/qbs/api/addsenior.php?id=" + user_id, {
            params: {
              real_name:this.real_name,
              age:this.age,
              school:this.school,
              production:this.production,
            }
          })
          .then(response => {
            console.log(response);
            // var data = res.data;
            // var json = eval("( '+ data +' )");
            // this.users = json.data;
            if(response.data.code == 200){
              Toast.success('添加成功，请重新登录');
              // location.reload();
               this.$router.push("./");
              //  Toast.success('请重新登录');
            }else{
              Toast.fail('添加失败');
            }
          })
       },
       onClickLeft(){
         this.$router.go(-1);
        //    console.log('houtui');
       }
    },
}
</script>

<style lang="scss" scoped>
.van-nav-bar {
  background: none;
}
.van-cell {
  background: none;
}
.van-nav-bar__title{
    font-size: 18px;
}

.content{
     height: 230px;
}
.content p{
    margin-bottom: 0;
        color: #323233;
    font-size: 14px;
    line-height: 24px;
    margin-left: 15px;
}
.introduce{
    margin: 10px;
    width: 70%;
    background-color: #fff1f4;
    border: 1px solid #ff1f0085;
}
.button{
    position: absolute;
    right: 20px;
    background-color: #f1acd3;
    border-radius: 20px;
}


</style>